home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / sb01.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-06-24  |  2KB  |  74 lines

  1. /* Example program how to use the routines of the soundblaster library
  2.  * for playing and recording files
  3.  */
  4.  
  5. #include <gppconio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "sb.h"
  9.  
  10. #define PLAY     0
  11. #define RECORD   1
  12.  
  13. int main(int argc, char **argv)
  14. {
  15.     unsigned long Rate = 12000;
  16.     int time = 2000;
  17.     char *Data;
  18.     int Length;
  19.     char *Name = "test.wav";
  20.     int i = 0;
  21.     int mode = PLAY;
  22.  
  23.     if(!sb_init()) {
  24.         printf("Cannot init card\n");
  25.         exit(1);
  26.     }
  27.     for(i = 1; i < argc; i++) {
  28.         if(*argv[i] == '-')
  29.             switch(argv[i][1]) {
  30.             case 'r' :
  31.             case 'R' :
  32.                 mode = RECORD;
  33.                 break;
  34.             case 'f' : 
  35.             case 'F' :
  36.                 if(!(Rate = atoi(&(argv[i][2])))) {
  37.                     printf("illegal recording frequency %s, using 12000\n",&(argv[i][2]));
  38.                     Rate = 12000;
  39.                 }
  40.                 break;
  41.             case 't' :
  42.             case 'T' :
  43.                 if(!(time = atoi(&(argv[i][2])))) {
  44.                     printf("illegal recording time %s ms, using 2000 ms\n",&(argv[i][2]));
  45.                     time = 2000;
  46.                 }
  47.                 break;
  48.             default :
  49.                 printf("illegal option %s\n",argv[i]);
  50.                 break;
  51.             }
  52.         else
  53.             Name = argv[i];
  54.     }
  55.     if(mode == PLAY) {
  56.         Data = get_wav_data(&Length, &Rate, Name);
  57.         if(!Data)
  58.             printf("cannot load file %s\n",Name);
  59.         SoundPlay(Rate, Data, Length);
  60.     } else {
  61.         Length = (time*Rate)/1000;
  62.         Data = malloc(Length);
  63.         printf("Recording %d ms with %d Hz, = %d byte\n",time, Rate, Length);
  64.         SoundRec(Rate, Data, Length);
  65.         printf("Ready\n");
  66.         put_wav_data(Data, Length, Rate, Name);
  67.     }
  68.     if(Data)
  69.         free(Data);
  70.     sb_cleanup();
  71.     argc = argc;    /* Just to shut up the warning gcc gives... */
  72.     return(1);
  73. }
  74.